
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2022/4/1
 * \* Time: 20:41
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class Demo25 {
    public static void main(String[] args) {
        //创建一个固定的线程数目的线程池，参数指定了线程个数
        ExecutorService pool = Executors.newFixedThreadPool(10);
//        //创建于给自动扩容的线程池，会根据任务量来自动扩容
//        Executors.newCachedThreadPool();
//        //创建一个只有一个线程的线程池
//        Executors.newSingleThreadExecutor();
//        //创建一个带有定时器功能的线程池，类似于Timer
//        Executors.newScheduledThreadPool(4000);

        for (int i = 0; i < 100; i++) {
            pool.submit(new Runnable() {
                @Override
                public void run() {
                    System.out.println("hello threadpool");
                }
            });
        }
    }
}
